home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr35 / tagdir.zip / TAGDIR.C < prev    next >
C/C++ Source or Header  |  1993-04-30  |  3KB  |  112 lines

  1. /* $Header */
  2.  
  3. #include <windows.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <ctype.h>
  7. #include "exports.h"
  8. #include "startup.h"
  9.  
  10. #ifdef __BORLANDC__
  11. LIBMAIN    /* defines the LibMain() function for Borland C */
  12. int DLL WEP(int nParam){return(1);}
  13. #endif
  14.  
  15. void DLL 
  16. _init()
  17. {
  18.     LibExport( "BOOL TagSetCWD BOOL");
  19.     LibExport( "BOOL tagDirHandler BOOL");
  20. }
  21.  
  22. /* Public functions:
  23.  *
  24.  * This event handler is called whenever a file buffer becomes current.
  25.  * It determines the directory in which the newly current file is
  26.  * located and make Codewright's idea of the current tag file relative
  27.  * to that directory.
  28.  *
  29.  * Only the basename and extension of the tagfile, as specified in the
  30.  * TagSetFile command, will be used.  Directory path information will
  31.  * be discarded.
  32.  *
  33.  * The purpose of this handler is to facilitate the use of Codewright
  34.  * for multiple projects.  By default, Codewright assumes only one tag
  35.  * file per session.  With this handler, the user need not bother about
  36.  * setting the tagfile name by hand when changing projects.
  37.  */
  38.  
  39.     
  40. BOOL DLL
  41. TagSetCWD (BOOL turnon)
  42. {
  43.     static HEVENT eHandle = NULL;
  44.     
  45.     if (turnon)
  46.     {
  47.         if (eHandle = EventRegister (EVENT_BUFFER_CURRENT, EVENT_NORMAL,
  48.             "tagDirHandler"))
  49.             return(TRUE);                // registration succeeded
  50.         else                            // registration failed
  51.             return(FALSE);
  52.     }
  53.     else if (eHandle)
  54.     {
  55.         if (!EventDeregister (eHandle))    // successfully deregistered
  56.             return(TRUE);
  57.         else                            // deregistration failed
  58.             return(FALSE);
  59.     }
  60. }
  61.  
  62. /*
  63.  * The event handler.  Returns TRUE if and only if it reset the
  64.  * tag file name.
  65.  */
  66.  
  67. long DLL
  68. tagDirHandler (long event, long data)
  69. {
  70.     LPSTR fnam;
  71.     char filedir[_MAX_PATH] = "";
  72.     LPSTR drive, path, base, ext;
  73.     
  74.     if (BufQIsSystem(BufQCurrentBuffer()))    // ignore system buffers
  75.         return((long)FALSE);
  76.  
  77.     if ((fnam = BufQFilename()) && *fnam)
  78.     {
  79.         if (!(fnam = StrNormalizePath(fnam)))    // can't get file's directory
  80.             return((long)FALSE);
  81.         if (!StrSplitpath(fnam, &drive, &path, NULL, NULL))
  82.             return((long)FALSE);
  83.         strcat(filedir, drive);
  84.         strcat(filedir, ":");
  85.         strcat(filedir, path);
  86.         StrFree(drive);
  87.         StrFree(path);
  88.         StrFree(fnam);
  89.     }
  90.  
  91.  
  92.     if ((fnam = (LPSTR)LibFunctionExec("TagQFile")) && *fnam) // reuse fnam
  93.     {
  94.         if (!(fnam = StrNormalizePath(fnam)))
  95.             return((long)FALSE);
  96.         if (!StrSplitpath(fnam, NULL, NULL, &base, &ext))
  97.             return((long)FALSE);
  98.         if (filedir[strlen(filedir)-1] != '\\')
  99.             strcat(filedir, "\\");
  100.         strcat(filedir, base);
  101.         strcat(filedir, ext);
  102.         StrFree(base);
  103.         StrFree(ext);
  104.         
  105.         TagSetFile(filedir);
  106.         StrFree(fnam);
  107.         return((long)TRUE);
  108.     }
  109.     return((long)FALSE);
  110. }
  111.  
  112.